package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 通用配置类型枚举
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-13
 */
public enum ConfigType implements BaseEnum {
    GLOBAL("GLOBAL", "全局配置"),
    COURSE("COURSE", "课程配置"),
    SUBJECT("SUBJECT", "科目配置"),
    PAPER_TYPE("PAPER_TYPE", "试卷类型配置"),
    DEPARTMENT("DEPARTMENT", "院系配置"),
    MAJOR("MAJOR", "专业配置"),
    CLASS("CLASS", "班级配置"),
    USER("USER", "用户配置"),
    SYSTEM("SYSTEM", "系统配置");

    private final String code;
    private final String description;

    ConfigType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static ConfigType fromCode(String code) {
        for (ConfigType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown config type code: " + code);
    }

    public static ConfigType fromDescription(String description) {
        for (ConfigType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown config type description: " + description);
    }

    @Override
    public String toString() {
        return code + " - " + description;
    }
}